import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/home/hall_of_fame/hall_of_fame_controller.dart';
import 'package:flutter_changdian_football/utils/pull/pull_smart_refresher.dart';
import 'package:flutter_changdian_football/widget/course/hall_of_fame_item.dart';
import 'package:flutter_changdian_football/widget/input/search_input_widget.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

// 名人堂
class HallOfFamePage extends StatelessWidget {
  const HallOfFamePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      backgroundColor: const Color(0xffF8FAF9),
      body: GetBuilder<HallOfFameController>(
        init: HallOfFameController(),
        builder: (hllOfFameController) {
          return Stack(
            children: [
              Container(
                height: 320.w,
                decoration: const BoxDecoration(
                  image: DecorationImage(image: AssetImage('assets/images/mrt_new_bg.png'), fit: BoxFit.fitWidth)
                ),
              ),
              SafeArea(
                child: Column(
                  children: [
                    Expanded(
                      child: ExtendedNestedScrollView(
                        physics: const BouncingScrollPhysics(),
                        controller: hllOfFameController.scrollController,
                        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
                          return [
                            SliverToBoxAdapter(
                              child: SizedBox(
                                width: double.infinity,
                                height: 140.w,
                                // padding: EdgeInsets.symmetric(horizontal: 17.w),
                                // child: Row(
                                //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                //   children: [
                                //     SizedBox(
                                //       child: Column(
                                //         mainAxisAlignment: MainAxisAlignment.center,
                                //         crossAxisAlignment: CrossAxisAlignment.start,
                                //         children: [
                                //           SizedBox(
                                //             height: 43.w,
                                //             width: 103.w,
                                //             child: Image.asset('assets/images/mrt_txt.png',),
                                //           ),
                                //           SizedBox(height: 4.w,),
                                //           SizedBox(
                                //             child: Text('Hall of Fame', style: TextStyle(fontSize: 15.sp, color: Colors.white),),
                                //           )
                                //         ],
                                //       ),
                                //     ),
                                //     SizedBox(
                                //       width: 160.w,
                                //       height: 160.w,
                                //       child: Image.asset('assets/images/jian.png', fit: BoxFit.fill,),
                                //     )
                                //   ],
                                // ),
                              ),
                            ),
                          ];
                        }, 
                        pinnedHeaderSliverHeightBuilder: () {
                          return kToolbarHeight - 60.w;
                        },
                        onlyOneScrollInBody: true,
                        body: SizedBox(
                          width: double.infinity,
                          height: double.infinity,
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children:  [
                              Stack(
                                clipBehavior: Clip.none,
                                children: [
                                  SafeArea(
                                    child: Container(
                                      margin: EdgeInsets.only(top: kToolbarHeight + 20.w),
                                      child: SearchInputWidget(
                                        hintText: '请输入关键字',
                                        radius: 30,
                                        controller: hllOfFameController.searchController,
                                        onSubmitted: () {
                                          EasyLoading.show();
                                          hllOfFameController.requestData(hllOfFameController.controller!);
                                        },
                                        isShowClose: hllOfFameController.searchController.text != '' ? true : false,
                                        onChange: () {
                                          hllOfFameController.update();
                                        },
                                        onClose: () {
                                          hllOfFameController.searchController.clear();
                                          hllOfFameController.update();
                                          EasyLoading.show();
                                          hllOfFameController.requestData(hllOfFameController.controller!);
                                        },
                                      ),
                                    )
                                  ),

                                  Positioned(
                                    top: -100.w,
                                    child: Container(
                                      width: MediaQuery.of(context).size.width,
                                      height: 160.w,
                                      padding: EdgeInsets.symmetric(horizontal: 17.w),
                                      child: Row(
                                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                        children: [
                                          SizedBox(
                                            child: Column(
                                              mainAxisAlignment: MainAxisAlignment.center,
                                              crossAxisAlignment: CrossAxisAlignment.start,
                                              children: [
                                                SizedBox(
                                                  height: 43.w,
                                                  width: 103.w,
                                                  child: Image.asset('assets/images/mrt_txt.png',),
                                                ),
                                                SizedBox(height: 4.w,),
                                                SizedBox(
                                                  child: Text('Hall of Fame', style: TextStyle(fontSize: 15.sp, color: Colors.white),),
                                                )
                                              ],
                                            ),
                                          ),
                                          SizedBox(
                                            width: 160.w,
                                            height: 160.w,
                                            child: Image.asset('assets/images/jian.png', fit: BoxFit.fill,),
                                          )
                                        ],
                                      ),
                                    )
                                  )
                                ],
                              ),
              
                              SizedBox(height: 10.w,),
              
                              Expanded(
                                child: RefreshWidget<HallOfFameController>(
                                  child: ListView.separated(
                                  itemCount: hllOfFameController.userRankList.length,
                                  physics: const BouncingScrollPhysics(),
                                  padding: EdgeInsets.only(bottom: 10.w, left: 17.w, right: 17.w),
                                  separatorBuilder: (context, index) {
                                    return SizedBox(height: 4.w,);
                                  },
                                  itemBuilder: (BuildContext context, int index) {
                                    return HallOfFameItem(
                                      index: index
                                    );
                                  },
                                                              ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    )
                  ],
                ),
              ),


              Positioned(
                top: 0,
                left: 0,
                right: 0,
                child: PreferredSize(
                  preferredSize: const Size.fromHeight(kToolbarHeight), // 设置 AppBar 的高度为 0
                  child: AppBar(
                    elevation: 0, 
                    backgroundColor: const Color(0xffF8FAF9).withAlpha(hllOfFameController.titleAlpha),
                    iconTheme: IconThemeData(
                      color: hllOfFameController.titleAlpha <= 200 ? Colors.white : const Color(0xff333333)
                    ),
                    title: Text('名人堂', style: TextStyle(fontSize: 16.sp, color: const Color(0xff333333).withAlpha(hllOfFameController.titleAlpha)),),
                    centerTitle: true,
                  ),
                ),
              )
            ],
          );
        }
      ),
    );
  }

}